package com.hyjy.music.bean

import com.hyjy.music.util.convertToPinYin
import java.io.Serializable

data class MusicBean(
    var name: String,
    var title: String,
    var singer: String,
    var album: String,
    var url: String,
    var size: Long,
    var duration: Long,
    var id: Long,
    var albumId: Long,
    var embedPic: ByteArray?
) : Serializable, Comparable<MusicBean> {
    // 上次播放到哪了
    var lastPlayProgress = 0

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as MusicBean

        if (name != other.name) return false
        if (title != other.title) return false
        if (singer != other.singer) return false
        if (album != other.album) return false
        if (url != other.url) return false
        if (size != other.size) return false
        if (duration != other.duration) return false
        if (id != other.id) return false
        if (albumId != other.albumId) return false
        if (embedPic != null) {
            if (other.embedPic == null) return false
            if (!embedPic.contentEquals(other.embedPic)) return false
        } else if (other.embedPic != null) return false

        return true
    }

    override fun hashCode(): Int {
        var result = name.hashCode()
        result = 31 * result + title.hashCode()
        result = 31 * result + singer.hashCode()
        result = 31 * result + album.hashCode()
        result = 31 * result + url.hashCode()
        result = 31 * result + size.hashCode()
        result = 31 * result + duration.hashCode()
        result = 31 * result + id.hashCode()
        result = 31 * result + albumId.hashCode()
        result = 31 * result + (embedPic?.contentHashCode() ?: 0)
        return result
    }

    override fun compareTo(other: MusicBean): Int {
        return title.convertToPinYin().compareTo(other.title.convertToPinYin())
    }
}